// pages/permission/permission.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city: '',
    plot: '',
    floor: '',
    unitNum:'',//单元数
    floorLevel:'',//楼层数量
    houseNumber:'' ,
    isSuccess: false,
    bid:'',
    uid:'',
    fid:'',
    floorNumber:'',//楼牌号
    hid:'',
    nameFloNum:"",
    cid:'',
  },
  //toSlectFloor
  toSelectPlot: function() {
    wx.navigateTo({
      url: './selectPlot/selectPlot',
    })
  },
  handleValidate(){
    wx.showToast({
      title: '请先选择小区',
      icon: 'loading',
      duration: 2000
    })
  },
  toSlectPlots: function() {
    var that = this;
    if(this.data.city == '') {
      return 
    } else {
      that.toSelectPlot();
    }
  },
  toSlectFloor: function() {
    var that = this;
    if(this.data.city == ''){
      return
    } else {
      wx.navigateTo({
        url: './selectFloor/selectFloor?obj='+JSON.stringify({city: that.data.city,plot: that.data.plot,type:3}),
      })
    }
  },
  //选择单元跳转
  toSlectUnit:function(){
    
    var that = this;
    if(this.data.city == ''){
      return
    } else {
      wx.navigateTo({
        url: './selectFloor/selectFloor?obj='+JSON.stringify({city: that.data.city,plot: that.data.plot,type:4,bid:that.data.bid}),
      })
    }
  },
  //选择楼层跳转toSlectFloorLevel
  toSlectFloorLevel:function(){
    
    var that = this;
    if(this.data.city == ''){
      return
    } else {
      wx.navigateTo({
        url: './selectFloor/selectFloor?obj='+JSON.stringify({city: that.data.city,plot: that.data.plot,type:5,uid:that.data.uid}),
      })
    }
  },
  //楼牌号跳转
  toSlectFloorNum:function(){
    var that = this;
    if(this.data.city == ''){
      return
    } else {
      
      
      wx.navigateTo({
        url: './selectFloor/selectFloor?obj='+JSON.stringify({city: that.data.city,plot: that.data.plot,type:6,fid:that.data.fid}),
      })
    }
  },
  getFloor: function(e) {
    if(e.detail.value == ''){
      this.setData({
        isSuccess: true
      })
    } else {
      this.setData({
        houseNumber: e.detail.value, 
        isSuccess: false
      })
    }
  },
  next: function(){

    
    console.log(this.data)
    let dataObj=JSON.stringify(this.data)
    wx.navigateTo({
      url: '../info/info?data='+dataObj,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    console.log(options,'ppp')
    let arr = Object.keys(options)
    
    var that = this;
    if(arr.length == 0){
      return
    } else {
      let info = JSON.parse(options.obj)
      that.setData({
        city: info.city,
        plot: info.plot,
        floor: info.floor,
        bid:info.bid,
        unitNum:info.unitNum,
        floorLevel:info.nameLevel,
        uid:info.uid,
        fid:info.fid
      })
    }
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {

    
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    let json = currPage.data.mydata;
    
    let unitJson=currPage.data.unitdata;//单元
    let levelJson=currPage.data.leveldata
    let floorNumDataJson=currPage.data.floorNumData
    
    //单元
    if (unitJson) {
      this.setData({
    //  fid:json.fid,
      uid:unitJson.uid||'',
      unitNum:unitJson.unitNum
      })
    }
    //楼层
    if (levelJson) {
      
      this.setData({
        floorLevel:levelJson.nameLevel,
        fid:levelJson.fid||'',
        //  unitNum:unitJson.unitNum
         })
    }
    //门牌号
    if (floorNumDataJson) {
      
      this.setData({
       
        hid:floorNumDataJson.hid||'',
        nameFloNum:floorNumDataJson.nameFloNum
         })
    }
    //楼栋
    this.setData({
      city: json.city,
      cid:json.cid,
      plot: json.plot,
      floor: json.floor,
      bid:json.bid,
      unitNum:json.unitNum,
      floorLevel:json.nameLevel,
      isSuccess:json.buttonShow


    })
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})